import { _decorator, Component, find, input, Input, EventKeyboard, KeyCode, SpriteFrame, director, } from 'cc';
import YangLeGeYang_GameManager from '../../SubGame/YangLeGeYang/Script/Manager/YangLeGeYang_GameManager';
// import ChengYu_Main from '../../SubGame/ChengYu/game/ChengYu/Script/XXL/Manager/ChengYu_Main';
// import JiuJiuXiaoDongWu_GameManager from '../../SubGame/JiuJiuXiaoDongWu/Script/JiuJiuXiaoDongWu_GameManager';
import { LianLianKan } from '../../SubGame/LianLianKan/script/LianLianKan';
import DaoShuiPaiXu_GameManager from '../../SubGame/DaoShuiPaiXu/Script/DaoShuiPaiXu_GameManager';
import RuntimeScrollSaverSimple, { GLOBAL_MAP_NAME } from '../UI/RuntimeScrollSaver';
import SpiderSolitaire_GameFunction from '../../SubGame/SpiderSolitaire/Script/SpiderSolitaire_GameFunction';
import SpiderSolitaire_GameManager from '../../SubGame/SpiderSolitaire/Script/SpiderSolitaire_GameManager';

const { ccclass, property } = _decorator;

@ccclass('SSS_InputManager')
export default class SSS_InputManager extends Component {
        static Instance: SSS_InputManager;

        onLoad() {
                SSS_InputManager.Instance = this;

                input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
                // input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
        }

        async onKeyDown(event: EventKeyboard) {
                if (event.keyCode == KeyCode.ARROW_UP || event.keyCode == KeyCode.KEY_W) {
                        // console.log(`up`);
                        // SS_GameManager.Instance.上一关();
                }
                if (event.keyCode == KeyCode.ARROW_DOWN || event.keyCode == KeyCode.KEY_S) {
                        // console.log(`down`);
                        // SS_GameManager.Instance.下一关();
                }
                if (event.keyCode == KeyCode.ARROW_LEFT || event.keyCode == KeyCode.KEY_A) {
                        // console.log(`left`);
                        // SS_GameManager.Instance.上一关();
                        YangLeGeYang_GameManager.Instance?.上一关();
                        // ChengYu_Main.Instance?.上一关();

                        // JiuJiuXiaoDongWu_GameManager.Instance?.上一关();
                        LianLianKan.Instance?.上一关();

                        DaoShuiPaiXu_GameManager.Instance?.上一关();

                        // LianLianKan_GameData.CurrentLevelIndex--;
                        // let currentSceneName = director.getScene().name;
                        // director.loadScene(`LianLianKan_Game_Scene`);
                }
                if (event.keyCode == KeyCode.ARROW_RIGHT || event.keyCode == KeyCode.KEY_D) {
                        console.log(`right`);
                        // SS_GameManager.Instance.下一关();

                        YangLeGeYang_GameManager.Instance?.下一关();
                        // ChengYu_Main.Instance?.下一关();

                        // JiuJiuXiaoDongWu_GameManager.Instance?.下一关();
                        LianLianKan.Instance?.下一关();

                        DaoShuiPaiXu_GameManager.Instance?.下一关();

                        // LianLianKan_GameData.CurrentLevelIndex++;
                        // let currentSceneName = director.getScene().name;
                        // director.loadScene(`LianLianKan_Game_Scene`);
                }

                if (event.keyCode == KeyCode.SPACE) {
                        // console.log(`空格`);

                        for (let col = 1; col <= 10; col++) {
                                for (let row = 1; row <= 13; row++) {
                                        let id = row;
                                        await SpiderSolitaire_GameFunction.CreateCard(col, row, id);
                                        // await SpiderSolitaire_GameFunction.CreateCard(col, 2, 2);
                                        // await SpiderSolitaire_GameFunction.CreateCard(col, 3, 3);
                                }


                                // await SpiderSolitaire_GameFunction.CreateCard(col, 1, 1);
                                // await SpiderSolitaire_GameFunction.CreateCard(col, 2, 2);
                                // await SpiderSolitaire_GameFunction.CreateCard(col, 3, 3);
                        }



                        // await SpiderSolitaire_GameFunction.CreateCard(2, 1, 4);
                        // await SpiderSolitaire_GameFunction.CreateCard(2, 2, 5);
                        // await SpiderSolitaire_GameFunction.CreateCard(2, 3, 6);

                        // await SpiderSolitaire_GameFunction.CreateCard(3, 1, 7);
                        // await SpiderSolitaire_GameFunction.CreateCard(3, 2, 8);
                        // await SpiderSolitaire_GameFunction.CreateCard(3, 3, 9);

                        // await SpiderSolitaire_GameFunction.CreateCard(4, 1, 10);
                        // await SpiderSolitaire_GameFunction.CreateCard(4, 2, 11);
                        // await SpiderSolitaire_GameFunction.CreateCard(4, 3, 12);


                        await new Promise(res => SpiderSolitaire_GameManager.Instance.scheduleOnce(res, 0.1));

                        SpiderSolitaire_GameFunction.sortByY();



                        // console.log(`GLOBAL_MAP_NAME`, GLOBAL_MAP_NAME);

                        // JiuJiuXiaoDongWu_GameData.fitToScreenWithRotation(JiuJiuXiaoDongWu_GameManager.Instance.container);

                        // LianLianKan.Instance.onVictory();
                }

                if (event.keyCode == KeyCode.ESCAPE) {
                        // SS_UIManager.Instance.CreatePanel(`UI/SettingPanel`, SettingPanel);
                }
                if (event.keyCode == KeyCode.NUM_1) {
                        console.log("num1");

                        SpiderSolitaire_GameFunction.sortByY();


                        // RuntimeScrollSaverSimple.Instance.保存()

                        // RuntimeScrollSaverSimple.Instance.读取()
                        // JiuJiuXiaoDongWu_GameData.centerHorizontally(JiuJiuXiaoDongWu_GameManager.Instance.container);
                        // SS_GameManager.Instance.成功()
                        // UI.Instance.CreatePanel_sub(`TurkishTetris_Prefab`, `UI/TurkishTetris_LosePanel`, TurkishTetris_LosePanel);
                }
                if (event.keyCode == KeyCode.NUM_2) {
                        console.log("num2");
                        // SS_GameManager.Instance.失败()
                        // RuntimeScrollSaverSimple.Instance.保存()
                        RuntimeScrollSaverSimple.Instance.读取()
                }
                if (event.keyCode == KeyCode.NUM_3) {
                        // console.log("num3");
                        // SS_AudioManager.Instance.pause();
                }
                if (event.keyCode == KeyCode.NUM_4) {
                        // console.log("num4");
                        // SS_AudioManager.Instance.resume();
                }
        }

        // onKeyUp(event: EventKeyboard) { }
}